Final Project

Bakari Moitt

2023-01-31

Intro:
Hi and welcome to my final project presentation. Below I will build graphs to replicate that of a scientific report published by Christine Nicol of Royal Veterinary College and Claire Weeks of University of Bristol. Their report is about the widespread issue of injurious pecking among laying hens. They are looking at the ability of hens in captivity to care for their beaks accordingly when generations have not been doing so and in the case that they can, what tools would need to be present in the pen.

Initially, my plan was to make a personal website detailing the movies that I had watched during j-term and ranking them accordingly, but that proved to be quite difficult. Since I could only start on the final project post our class on Tuesday I was not able to get any troubleshooting help, so I decided making graphs was the next best thing.

Step 1: obtain the data
1. Download the data set from datadryad.org. I used this website for the beak data: https://datadryad.org/stash/dataset/doi:10.5061%2Fdryad.2bvq83bs3
2. Click the link provided that will guide you to orchid.org to find the report figures. - insert pic 3. Under works you will find title that relates to pecking and beaks. Click the DOI code. - insert pic 4. Now that you have open access to the article, you can scroll a bit down and clock browse figure. This will show you all the figures within the article so you know what to copy. Take screenshots of the pictures so you can refer back to them as you work on the graph replication.

Step 2: Upload your data: 1.

library(ggplot2)
library(ggthemes)
library(patchwork)
library(plyr)

Quail1<- read.table(file="final project/Trans-ovo quail 15.csv", header = TRUE, sep = ",")
head(Quail1)
##          Nest Permethrin Number Heart.Mass..g. Heart.Length..mm.
## 1 .2 g cotton    Control      1         0.0334              5.29
## 2 .2 g cotton    Control      2         0.0355              6.23
## 3 .2 g cotton    Control      3         0.0206              4.83
## 4 .2 g cotton    Control      4         0.0337              6.53
## 5 .2 g cotton    Control      5         0.0251              5.29
## 6 .2 g cotton    Control      6         0.0312              5.66
##   Heart.Width..mm. Heart.Depth..mm. Mass..g. Right.Tarsus..mm. Beak..mm.
## 1             3.90             3.04   3.9571             12.54     5.137
## 2             3.90             3.63   4.3403             13.07     6.370
## 3             3.21             3.16   3.2672             10.78     5.344
## 4             4.58             3.32   4.8308             13.25     4.655
## 5             3.74             2.49   3.3593             11.59     4.938
## 6             3.69             3.08   4.5668             13.51     6.669
##    Toe..mm. Eye.Diameter..mm. Head.Diameter..mm. Heart.rates
## 1  8.556757             4.668             15.900         264
## 2  8.966975             4.587             15.771         338
## 3  8.401623             4.085             17.166          NA
## 4  9.539726             3.855             17.646         285
## 5  8.612118             4.122             15.075          NA
## 6 10.761066             4.267             15.776         209
Quail2<- read.table(file="final project/Trans-ovo qual 5.csv", header = TRUE, sep = ",")
head(Quail2)
##   Embryo.Number Nest.Cotton.Weight Dose Treatment Mass Heart.Rate Stage
## 1             1                0.8    0   Control 0.38      132.6    33
## 2             2                0.8    0   Control 0.51       84.0    32
## 3             3                0.8    0   Control 0.48      105.0    31
## 4             4                0.8    0   Control 0.40      102.3    33
## 5             5                0.8    0   Control 0.48      110.0    31
## 6             6                0.8    0   Control 0.58      106.6    33
##   Head.Width..mm. Eye.Width..mm. Body.Length..mm. Hindbrain..Fluid.Solid
## 1           7.214          4.396           17.685                  Fluid
## 2           5.810          3.131           16.984                  Fluid
## 3           7.173          3.459           18.606                  Fluid
## 4           6.644          5.016           17.518                  Fluid
## 5           7.579          4.590           15.673                  Fluid
## 6          10.853          6.375           18.755                  Fluid
##   Forebrain..Fluid.Solid Forebrain.Width..mm. Forebrain.Height..mm.
## 1                  Fluid                3.716                 1.078
## 2                  Fluid                2.981                 0.740
## 3                  Fluid                3.462                 0.990
## 4                  Fluid                3.262                 0.959
## 5                  Solid                3.075                 1.110
## 6                  Fluid                4.054                 0.873
##   Forebrain.Area..cm2. Hindbrain.Width..cm. Hindbrain.width..mm.
## 1             4.005848                0.136                 1.36
## 2             2.205940                0.211                 2.11
## 3             3.427380                0.101                 1.01
## 4             3.128258                0.120                 1.20
## 5             3.413250                0.200                 2.00
## 6             3.539142                0.117                 1.17
##   Hindbrain.Height..mm. Hindbrain.Area..cm2. Ventricular.Apex Atrium
## 1                  3.16             0.042976          pointed      1
## 2                  3.32             0.070052                      NA
## 3                  3.32             0.033532          pointed      2
## 4                  2.47             0.029640          pointed      2
## 5                  3.71             0.074200            round      0
## 6                  2.56             0.029952          pointed      2
##   Heart.Weight..g.
## 1           0.0039
## 2               NA
## 3           0.0041
## 4           0.0008
## 5           0.0002
## 6           0.0032

Step 3: Figure 1 Here is a picture of my intended replication: Figure 1

### Making graph 1
###### looking at my data given in the form of a data frame I labeled Quail1, I can see that the first graph in  figure 1 uses columns: Treatment and Mass. I know this because the while the treatment column matches the permethrin column in Quail1, the categorizing column (nest weight in cotton) is only present in Quail2 for both .8g and .2g. 

#making my SEM bars
#data_summary <- function(data, varname, groupnames){
 # require(plyr)
#  summary_func <- function(x, col){
#    c(mean = mean(x[[col]], na.rm=TRUE),
#      sd = sd(x[[col]], na.rm=TRUE))
#  }
 # data_sum<-ddply(data, groupnames, .fun=summary_func,
   #               varname)
 # data_sum <- rename(data_sum, c("mean" = varname))
# return(data_sum)
#}

#df2 <- data_summary(Quail1, varname="Mass..g.", 
        #            groupnames=c("Permethrin", "Nest"))
# Convert Nest to a factor variable
#df2$Nest=as.factor(df2$Nest)
#head(df2)
# reverse order of legend
#df2$Nest <- factor(df2$Nest, levels = rev(levels(df2$Nest)))
#labels for legend
L <- c("A","A","B","C")
l1<- c(5,4,3,2.5)
#make the graph
graph1<- ggplot(data=Quail1,
              aes(x= Permethrin, y=Mass..g., fill=Nest)) + geom_bar(position="dodge", stat="identity", width=0.5) +
  ylab("Body mass(g)") +
  xlab("")+
  labs( tag= "(A)")
  stat_summary(fun.data = mean_se, 
               geom="errorbar",
               width = 0.2)
## geom_errorbar: na.rm = FALSE, orientation = NA, width = 0.2
## stat_summary: fun.data = function (x, mult = 1) 
## {
##     x <- stats::na.omit(x)
##     se <- mult * sqrt(stats::var(x)/length(x))
##     mean <- mean(x)
##     data_frame0(y = mean, ymin = mean - se, ymax = mean + se, .size = 1)
## }, fun = NULL, fun.max = NULL, fun.min = NULL, fun.args = list(), na.rm = FALSE, orientation = NA
## position_identity
graph1 + theme_classic() + scale_fill_grey( start = .1, end = .3, breaks = c("0.2 g cotton", "0.8 g cotton")) + guides(fill=guide_legend(title=""),) +
  theme(axis.text = element_text(face="bold"), panel.background = element_rect(fill = 'gray94', color = 'black'),
  legend.position="left") 

### Making graph 2
###### looking at my data given in the form of a data frame I labeled Quail1, I can see that the first graph in  figure 1 uses columns: Treatment and Right.Tarsus. I know this because the while the treatment column matches the Permethrin column in Quail2, the dependent column (Tarsus length) is only present in Quail1. 
#reverse the legend
Quail1$Nest <- factor(Quail1$Nest, levels = rev(levels(Quail1$Nest)))
#make the graph
graph2<- ggplot(data=Quail1,
              aes(x= Permethrin, y=Right.Tarsus..mm., fill=Nest)) + geom_bar(position="dodge", stat="identity", width=0.5) +
  ylab("Tarsus Length (mm)") +
  xlab("") +
  labs( tag="(B)")
graph2 + theme_classic() + scale_fill_grey( start = .1, end = .3, breaks = c("0.2 g cotton", "0.8 g cotton")) + guides(fill=guide_legend(title=""),) +
  theme(axis.text = element_text(face="bold"), panel.background = element_rect(fill = 'gray94', color = 'black'),
  legend.position="left")

Step 4: Figure 2 Here is a picture of my intended replication: Figure 2 Step 5: Figure 3 Here is a picture of my intended replication: Figure 3

Step 6: Figure 4 Here is a picture of my intended replication: Figure 4

Step 10: Plausible troubleshooting: